package com.jumi.microservice.controller;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jm.member.common.core.web.page.TableDataInfo;
import com.jumi.microservice.dto.request.BaseUserRequest;
import com.jumi.microservice.enums.CommonEnum;
import com.jumi.microservice.enums.JoinType;
import com.jumi.microservice.service.IJmUserService;
import com.jumi.microservice.service.IJmUserTeamService;
import com.jumi.microservice.service.PageService;
import com.jumi.microservice.util.WrapperUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.function.Function;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 要挑客户管理团队
 * @since 2020-07-14
 */
@RestController
@RequestMapping("/jm-user-team")
@Api(value = "我的团队信息",tags = "我的团队信息")
public class JmUserTeamController {

    @Autowired
    IJmUserService userService;
    @Autowired
    IJmUserTeamService teamService;


    @PostMapping("/getMyTeamDetail")
    @ApiOperation("我的团队详细信息")
    public TableDataInfo getMyTeamDetail(BaseUserRequest request,JoinType joinType, Integer current, Integer size){
        Integer uid = request.getId();
        userService.checkUserExist(uid);
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("is_del", CommonEnum.否);
        if(ObjectUtil.isNotEmpty(joinType))
            wrapper.eq("join_type", joinType);
        wrapper.eq("team_uid",uid);
        wrapper.select("uid");
        //我的团队信息
        List<Integer> uids = teamService.listObjs(wrapper, (Function<Object, Object>) o -> Integer.valueOf(o.toString()));
        //查询用户信息
        request.setId(null);
        QueryWrapper userWrapper = WrapperUtil.getWrapper(null, request);
        uids.add(-1);
        userWrapper.in("id",uids);
        Page page = userService.getPage(new Page(current, size), userWrapper);
        TableDataInfo dataTableInfo = PageService.getDataTableInfo(page);
        return dataTableInfo;
    }
}
